package secondBrush.array;

import jdk.swing.interop.SwingInterOpUtils;

import java.util.Arrays;
import java.util.Scanner;

public class E07KamaCoder44 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[][] arr = new int[n][m];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = scanner.nextInt();
                sum += arr[i][j];
            }
        }

        //横向
        int[] transverse = new int[m];
        int transverseCur;
        for (int i = 0; i < m ; i++) {
             transverseCur = 0;
            for (int j = 0; j < n; j++) {
                transverseCur += arr[i][j];
                transverse[i] = transverseCur;
            }
        }



        //纵向
        int[] longitudinal = new int[n];
        int longitudinalCur;
        for (int i = 0; i < n; i++) {
            longitudinalCur = 0;
            for (int j = 0; j < m; j++) {
                longitudinalCur += arr[j][i];
                longitudinal[i] = longitudinalCur;
            }
        }


        //横向划分
        int result = Integer.MAX_VALUE;
        int curr = 0;
        for (int i = 0; i < n; i++) {
            curr += transverse[i];
            result = Math.min(result, Math.abs(sum - 2 * curr));
        }

        //纵向划分
        int currY = 0;
        for (int i = 0; i < m; i++) {
            currY += longitudinal[i];
            result = Math.min(result, Math.abs(sum - 2 * currY));
        }

        System.out.println(result);




    }
}
